import time
from datetime import date

from django.db import models


# Create your models here.

# 创建用户信息表
class UserInfo(models.Model):
    userId = models.AutoField(primary_key=True, serialize=True,  verbose_name='用户id')
    email = models.EmailField(max_length=50, verbose_name='邮箱')
    username = models.CharField(max_length=24, verbose_name='用户名', db_index=True, unique=True)
    password = models.CharField(max_length=24, verbose_name='密码')
    class Meta:
        db_table = "userInfo"

# 创建自选股表
class UserStock(models.Model):
    id = models.AutoField(primary_key=True)
    userId = models.IntegerField()
    ts_code = models.TextField()
    status = models.TextField()
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now = True)
    class Meta:
        db_table = "userStock"


class StockInfo(models.Model):
    stockId = models.AutoField(primary_key=True, serialize=True, verbose_name='股票id')
    ts_code = models.TextField(verbose_name='股票代码')
    symbol = models.IntegerField(verbose_name='symbol')
    name = models.TextField(verbose_name='名称')
    area = models.TextField(verbose_name='地区')
    industry = models.TextField(verbose_name='行业')
    list_date = models.TextField(verbose_name='上市日期')
    open = models.FloatField(verbose_name='开盘价')
    close = models.FloatField(verbose_name='收盘价')
    pre_close = models.FloatField(verbose_name='上一日收盘价')
    change = models.FloatField(verbose_name='涨跌幅(今日收盘价-上一日收盘价)')
    pct_chg = models.FloatField(verbose_name='(今日收盘价-上一日收盘价)/上一日收盘价')
    vol = models.FloatField(verbose_name='成交量')
    amount = models.FloatField(verbose_name='总量')

    class Meta:
        db_table = "stockInfo"

class StockDailyRecord(models.Model):
    recordId = models.AutoField(primary_key=True, serialize=True, verbose_name='股票id')
    ts_code = models.TextField(verbose_name='股票代码')
    trade_date = models.TextField(verbose_name='日期')
    open = models.FloatField(verbose_name='开盘价')
    high = models.FloatField(verbose_name='最高价')
    low = models.FloatField(verbose_name='最低价')
    close = models.FloatField(verbose_name='收盘价')
    pre_close = models.FloatField(verbose_name='上一日收盘价')
    change = models.FloatField(verbose_name='今日收盘价-上一日收盘价')
    pct_chg = models.FloatField(verbose_name='(今日收盘价-上一日收盘价)/上一日收盘价')
    vol = models.FloatField(verbose_name='成交量')
    amount = models.FloatField(verbose_name='总量')

    class Meta:
        db_table = "stockDailyRecord"

